package com.huawei.appmarket.service.apppermission.view;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.huawei.appmarket.service.apppermission.bean.GroupPermissionInfo;
import com.huawei.appmarket.service.apppermission.bean.PermissionInfo;
import com.huawei.appmarket.service.apppermission.bean.SingleAppPermissionInfo;
import o.Logger;
import o.ewm.h;
import o.ewm.j;

public class PermissionAdapter extends BaseAdapter {
    private static final int ITEM_TYPE_GROUPDESC = 0;
    private static final int ITEM_TYPE_PERMISSIONLABEL = 1;
    private static final String TAG = "PermissionAdapter";
    private Context mContext;
    private SingleAppPermissionInfo mGroupPermissions;

    static class a {
        private TextView ˎ;

        private a() {
        }
    }

    static class b {
        private TextView ˏ;

        private b() {
        }
    }

    public PermissionAdapter(Context context, SingleAppPermissionInfo singleAppPermissionInfo) {
        this.mContext = context;
        this.mGroupPermissions = singleAppPermissionInfo;
    }

    public int getViewTypeCount() {
        return 2;
    }

    public int getItemViewType(int i) {
        int i2 = -1;
        for (GroupPermissionInfo groupPermissionInfo : this.mGroupPermissions.ॱ()) {
            i2++;
            if (i == i2) {
                return 0;
            }
            int size = groupPermissionInfo.ˏ().size() + i2;
            if (i <= size) {
                return 1;
            }
            i2 = size;
        }
        return 1;
    }

    public Object getItem(int i) {
        int i2 = -1;
        for (GroupPermissionInfo groupPermissionInfo : this.mGroupPermissions.ॱ()) {
            i2++;
            if (i == i2) {
                return groupPermissionInfo.ˎ();
            }
            int size = groupPermissionInfo.ˏ().size();
            i2 += size;
            if (i <= i2) {
                return ((PermissionInfo) groupPermissionInfo.ˏ().get((size - (i2 - i)) - 1)).ॱ();
            }
        }
        return "";
    }

    public int getCount() {
        int i = 0;
        for (GroupPermissionInfo ˏ : this.mGroupPermissions.ॱ()) {
            i = ˏ.ˏ().size() + (i + 1);
        }
        return i;
    }

    public long getItemId(int i) {
        return (long) i;
    }

    public boolean isEnabled(int i) {
        return false;
    }

    public View getView(int i, View view, ViewGroup viewGroup) {
        String str = (String) getItem(i);
        int itemViewType = getItemViewType(i);
        switch (itemViewType) {
            case 0:
                return getGroupPermissionView(view, str);
            case 1:
                return getPermissionLabelView(view, str);
            default:
                Logger.e(TAG, "error itemType:" + itemViewType);
                return view;
        }
    }

    @NonNull
    private View getPermissionLabelView(View view, String str) {
        b bVar;
        if (view == null || !(view.getTag() instanceof b)) {
            view = LayoutInflater.from(this.mContext).inflate(h.ʼ, null);
            b bVar2 = new b();
            bVar2.ˏ = (TextView) view.findViewById(j.ᵎᐝ);
            view.setTag(bVar2);
            bVar = bVar2;
        } else {
            bVar = (b) view.getTag();
        }
        bVar.ˏ.setText(str);
        return view;
    }

    @NonNull
    private View getGroupPermissionView(View view, String str) {
        a aVar;
        if (view == null || !(view.getTag() instanceof a)) {
            view = LayoutInflater.from(this.mContext).inflate(h.ˏॱ, null);
            a aVar2 = new a();
            aVar2.ˎ = (TextView) view.findViewById(j.ᵎᐝ);
            view.setTag(aVar2);
            aVar = aVar2;
        } else {
            aVar = (a) view.getTag();
        }
        aVar.ˎ.setText(str);
        return view;
    }
}
